<template>
  <div>
    <van-cell-group border>
      <van-field
        v-model="password"
        label="密码"
        placeholder="请输入新密码"
        autofocus
      />
      <span class="text"
        >最少6位，包括至少1个大写字母，1个小写字母，1个数字，1个特殊字符</span
      >
    </van-cell-group>

    <van-button
      class="but"
      type="danger"
      round
      :disabled="!flag"
      block
      @click="register"
      >完成</van-button
    >
  </div>
</template>

<script>
import { doFinishRegister } from "../../api/user";
export default {
  data() {
    return {
      password: "",
    };
  },
  computed: {
    flag() {
      return /^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])(?=\S*[!@#$%^&*+-/?~·])\S*$/.test(
        this.password
      ); //密码强度校验，最少6位，包括至少1个大写字母，1个小写字母，1个数字，1个特殊字符"
    },
  },
  methods: {
    register() {
      doFinishRegister({
        tel: JSON.parse(localStorage.getItem("tel")),
        password: this.password,
      }).then((data) => {
        console.log(data);
      });
      this.$router.push("/login");
    },
  },
};
</script>

<style scoped>
.but {
  width: 80%;
  margin: 1rem auto;
}
.text {
  font-size: 12px;
  color: #ccc;
}
</style>